/**
 *  @file BinBuf.h
 */
#ifndef _BINBUF_H_
#define _BINBUF_H_

#include "../common/BaseObject.h"

namespace cppflib
{

namespace collections
{

/**
 *  A simple binary buffer class to hold any raw byte data
 */
class _DLLAPI BinBuf : public BaseObject
{
protected:
    u8_t * pData;   ///< buffer pointer
    sz_t len;       ///< length of buffer in bytes
    sz_t validLen;  ///< valid length of data

protected:
    void __Realloc(sz_t reqSize, bool isAlignBufferSize);

private:
    void InitInternal(void);

public:
    BinBuf(void);
    explicit BinBuf(sz_t reqSize);
    virtual ~BinBuf(void);

    virtual void Realloc(sz_t reqSize);
    virtual void SetValidLength(sz_t validLen);
    virtual void CopyData(const u8_t * pData, sz_t dataLen, bool isZeroTerm = false);
    virtual void AppendData(const u8_t * pData, sz_t dataLen, bool isZeroTerm = false);
    virtual void AppendInt(const int val);
    virtual void AppendUInt(const u32_t val);
    virtual void AppendHex(const u32_t val);
    virtual sz_t ReserveSpace(sz_t reqSize);
    virtual u8_t * GetValidEnd() const;
    virtual u8_t * GetBufferEnd() const;
    virtual u8_t * GetRawBuf() const;
    virtual sz_t GetLength() const;
    virtual sz_t GetValidLength() const;
    virtual sz_t GetSpaceLeft() const;
    virtual bool MoveData2Front(sz_t startOff);
    virtual void ClearBuf();
    
};

} // end of namespace collections


} // end of namespace cppflib


#endif
